home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / lptinit.com / LPTINIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-10-12  |  2.1 KB  |  47 lines

  1. {Copyright (C) 1990 by J. Scott Sanbar.  All Rights Reserved}
  2.  
  3. {LptInit initializes a printer and returns its status.      }
  4. {I have found using BIOS Interrupt $17 to be unreliable     }
  5. {in cases where a printer is disconnected or has a bad      }
  6. {cable.  This program seems more reliable and diagnostic.   }
  7.  
  8. {This program is hereby committed to the public domain and  }
  9. {may be altered, used and distributed freely by all.        }
  10.  
  11. {$M 1024,0,0}
  12. {$S-}
  13.  
  14. program LptInit;
  15.  
  16. var
  17.   Choice : string;
  18.   LptPort : byte;
  19.   Status, Control : byte;
  20.   BaseAddress : word;
  21.   Ticks : word absolute $0040:$006C; {Low word of timer ticks}
  22.   StartTicks,TTLTicks : word;
  23.  
  24. begin
  25.  writeln;
  26.  write('Which Lpt Port (1, 2 or 3)? ');
  27.  Choice := 'G';
  28.  readln(Choice);
  29.  LptPort := Ord(Choice[1]) - 48;
  30.  if (LptPort > 3) or (LptPort < 1) then begin writeln('Aborted');halt end;
  31.  BaseAddress := MemW[$0040:6 + LptPort * 2]; {Base address to access parallel port registers}
  32.  repeat until Ticks < $65262;                {If we are too close to hour mark, wait for turnover}
  33.  Control := Port[BaseAddress + 2];           {Read in control register}
  34.  Port[BaseAddress + 2] := Control and $FB;   {Toggle reset line on}
  35.  Port[BaseAddress + 2] := Control;           {Toggle off}
  36.  StartTicks := Ticks;                        {Start counting ticks}
  37.  repeat until (Port[BaseAddress + 1] and $80 = $80) or
  38.   (Ticks - StartTicks > 182);                {Wait until not busy or timeout (10 seconds)}
  39.  TTLTicks := Ticks - StartTicks;             {Get total time busy}
  40.  Status := Port[BaseAddress + 1];            {Get status register}
  41.  if Status = $00 then writeln('Invalid Printer Port') else
  42.   if TTLTicks < 2 then writeln('Printer off or cable disconnected') else {If not busy at all, bad cable or printer off}
  43.    if Status and $20 = $20 then writeln('Printer out of Paper') else
  44.     if Status and $B8 = $98 then begin writeln('Printer Online');halt;end else {printer OK, exit without error code}
  45.      writeln('Printer Off Line');            {This means printer is on, connected and has paper but is offline}
  46.  Halt(255); {Printer not ready - exit with error code}
  47. end.